package com.whq.thrift.api.web.base.serviceconf.db;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;

public interface ModuleInfoMapper {
	@Select("select * from t_module_info where module_id=#{moduleId}")
	@Results(
		value = {
			@Result(property="moduleId", column="module_id"),
			@Result(property="comment", column="comment"),
			@Result(property="owner", column="owner"),
			@Result(property="createTime", column="create_time"),
			@Result(property="updateTime", column="update_time"),
			@Result(property="forGateway", column="for_gateway"),
			@Result(property="errCodeMin", column="err_code_min"),
			@Result(property="errCodeMax", column="err_code_max"),
			@Result(property="moduleStatus", column="module_status"),
			@Result(property="servicePort", column="service_port"),
			@Result(property="moduleComment", column="module_comment")
		}
	)
	public ModuleInfo getRecordByKey(@Param("moduleId") String moduleId);
	
	@Insert("INSERT INTO t_module_info "
			+ " (module_id, comment, owner, create_time, update_time, for_gateway, err_code_min, err_code_max, module_status, service_port, module_comment) "
			+ " VALUES "
			+ " (#{moduleId}, #{comment}, #{owner}, #{createTime}, #{updateTime}, #{forGateway}, #{errCodeMin}, #{errCodeMax}, #{moduleStatus}, #{servicePort}, #{moduleComment})")
    public void addRecord(ModuleInfo moduleInfo);
    
	@SelectProvider(type = ModuleInfoSqlProvider.class, method = "getSelectRecordsSql")
	@Results(
			value = {
				@Result(property="moduleId", column="module_id"),
				@Result(property="comment", column="comment"),
				@Result(property="owner", column="owner"),
				@Result(property="createTime", column="create_time"),
				@Result(property="updateTime", column="update_time"),
				@Result(property="forGateway", column="for_gateway"),
				@Result(property="errCodeMin", column="err_code_min"),
				@Result(property="errCodeMax", column="err_code_max"),
				@Result(property="moduleStatus", column="module_status"),
				@Result(property="servicePort", column="service_port"),
				@Result(property="moduleComment", column="module_comment")
			}
		)
    public List<ModuleInfo> findRecordsByMap(@Param("moduleId") String moduleId, @Param("beginIndex") int beginIndex, @Param("maxCount") int maxCount);
	
	@SelectProvider(type = ModuleInfoSqlProvider.class, method = "getSelectCountSql")
    public int findRecordsCount(@Param("moduleId") String moduleId);
	
	@UpdateProvider(type = ModuleInfoSqlProvider.class, method = "getUpdateSql")
	public void updRecord(ModuleInfo moduleInfo);
	
	@Delete("delete from t_module_info where module_id=#{moduleId}")
	public void delRecord(@Param("moduleId") String moduleId);
	
	@Select("select * from t_module_info where for_gateway=#{forGateway} and module_status=#{moduleStatus}")
	@Results(
		value = {
			@Result(property="moduleId", column="module_id"),
			@Result(property="comment", column="comment"),
			@Result(property="owner", column="owner"),
			@Result(property="createTime", column="create_time"),
			@Result(property="updateTime", column="update_time"),
			@Result(property="forGateway", column="for_gateway"),
			@Result(property="errCodeMin", column="err_code_min"),
			@Result(property="errCodeMax", column="err_code_max"),
			@Result(property="moduleStatus", column="module_status"),
			@Result(property="servicePort", column="service_port"),
			@Result(property="moduleComment", column="module_comment")
		}
	)
	public List<ModuleInfo> findIsGateWayRecords(@Param("forGateway") int forGateway, @Param("moduleStatus") int moduleStatus);
}
